package com.spzx.channel.service.impl;

import com.spzx.channel.service.IndexService;
import com.spzx.common.core.constant.SecurityConstants;
import com.spzx.common.core.domain.R;
import com.spzx.product.api.domain.ProductSku;
import com.spzx.product.api.domain.vo.CategoryVo;
import com.spzx.product.api.service.RemoteCategoryService;
import com.spzx.product.api.service.RemoteProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class IndexServiceImpl implements IndexService {

    @Autowired
    private RemoteCategoryService remoteCategoryService;

    @Autowired
    private RemoteProductService remoteProductService;

    @Override
    public Map<String, Object> getIndexData() {
        //远程调用商品微服务获取一级分类
        R<List<CategoryVo>> firstLeveCategory = remoteCategoryService.getFirstLeveCategory(0L, SecurityConstants.INNER);
        //获取一级分类集合
        List<CategoryVo> firstLeveCategoryList = firstLeveCategory.getData();
        R<List<ProductSku>> topSale = remoteProductService.getTopSale(SecurityConstants.INNER);
        List<ProductSku> productSkuList = topSale.getData();

        //创建返回的map
        Map<String,Object> returnMap= new HashMap<>();
        //设置一级分类数据
        returnMap.put("categoryList",firstLeveCategoryList);
        //设置畅销商品
        returnMap.put("productSkuList",productSkuList);
        return returnMap;
    }
}
